﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SZSLSystem.Common;

namespace SZSLSystem.SalesManagement.Project
{
    public partial class List : SZSLSystem.Web.UI.ManagePage
    {
       const int PageSize = 20;
        protected void Page_Load(object sender, EventArgs e)
        {
            PageNavigator1.OnPageChange += new PageChangeHandler(PageNavigator1_OnPageChange);
            if (!Page.IsPostBack)
            {
                Bind(1);
            }
        }
        string Sql
        {
            get
            {
                if (ViewState["sql"] == null)
                    return " 1=1";
                else
                    return ViewState["sql"].ToString();
            }
            set
            {
                ViewState["sql"] = value;
            }
        }
        void PageNavigator1_OnPageChange(object send, int nPageIndex)
        {
            Bind(nPageIndex);
        }
        void Bind(int pageindex)
        {
            rptList.DataSource = new SZSLSystem.BLL.Pager().GetWherePagelist("OID", "[OID],[ProjectName],[ProjectAddress],[BuildCompany],[DesignCompany],[ConstructionCompany],[MarketingTel],[MarketingCompany],[QualitativeInspectCompany],[PropertyManagement]","Project", PageSize, pageindex, Sql, "OID", 1);
            rptList.DataBind();
            PageNavigator1.PageCount = PageCount;
            PageNavigator1.PageIndex = pageindex;
            PageNavigator1.RecordCount = TotalRowCount;
        }
        protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Del")
            {
                string tguid = e.CommandArgument.ToString();
                new SZSLSystem.BLL.Project().Delete(tguid);
                e.Item.Visible = false;
            }
        }
        int TotalRowCount
        {
            get
            {
                return new BLL.Pager().getCount("OID", "Project", Sql);

            }


        }

        protected int PageCount
        {
            get
            {
                if (TotalRowCount % PageSize == 0)
                    return TotalRowCount / PageSize;
                else
                    return (TotalRowCount / PageSize) + 1;
            }
        }
	protected void btnSearch_Click(object sender, EventArgs e)
	{
			// Sql=" (TLuojishangchu=0 or TLuojishangchu is null) ";
			 Sql="  1=1 ";
			string strErr="";
			
			string ProjectName=this.txtProjectName.Text;
			if(ProjectName!="")
			{
				 Sql +=" and ProjectName='"+ProjectName+"'";
			}		

			if(strErr!="")
			{
                JscriptMsg(350, 230, "错误提示", "<b>出现错误了！</b><br/>" + strErr, "", "Error");
				return;
			}
			Bind(1);
	}

    }
}
